using PhillyCodeCamp.Domain.Validation;
using PhillyCodeCamp.DTO;
using PhillyCodeCamp.Infrastructure;
using PhillyCodeCamp.Mappers;

namespace PhillyCodeCamp.Services
{
    public class ValidationService : IValidationService
    {
        private readonly ITaxReturnMapper _taxReturnMapper;

        public ValidationService() : this (DependencyResolver.Resolve<ITaxReturnMapper>())
        {
        }

        public ValidationService(ITaxReturnMapper taxReturnMapper)
        {
            _taxReturnMapper = taxReturnMapper;
        }

        public IBusinessRuleSet Validate(TaxDataDTO dto)
        {
            //first validation only validates types
            //so that mapping will succeed
            var brokenRoles = dto.Validate();

            if (brokenRoles.Count > 0)
                return brokenRoles;

             return _taxReturnMapper.MapTaxReturn(dto).Validate();
            }
        }
    }
